package it.irondev.appturismo.dao;

import it.irondev.appturismo.dao.example.EventsExample;
import it.irondev.appturismo.dao.provider.EventsSqlProvider;
import it.irondev.appturismo.entity.City;
import it.irondev.appturismo.entity.Event;
import it.irondev.appturismo.entity.Eventstype;
import it.irondev.appturismo.entity.Gallery;
import it.irondev.appturismo.entity.Language;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.springframework.context.annotation.Lazy;

public interface EventsMapper {
    @SelectProvider(type=EventsSqlProvider.class, method="countByExample")
    int countByExample(EventsExample example);

    @DeleteProvider(type=EventsSqlProvider.class, method="deleteByExample")
    int deleteByExample(EventsExample example);

    @Delete({
        "delete from Events",
        "where idEvents = #{idevents,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer idevents);

    @Insert({
        "insert into Events ( name, ",
        "city, address, location, ",
        "position, start_date, ",
        "end_date, type, ",
        "description, web, language)",
        "values (#{name,jdbcType=VARCHAR}, ",
        "#{city.idcity,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR}, #{location,jdbcType=VARCHAR}, ",
        "#{position,jdbcType=VARCHAR}, #{startDate,jdbcType=TIMESTAMP}, ",
        "#{endDate,jdbcType=TIMESTAMP}, #{type.ideventstype,jdbcType=INTEGER}, ",
        "#{description,jdbcType=VARCHAR}, #{web,jdbcType=VARCHAR}, #{language.idlanguage,jdbcType=INTEGER})"
    })
	@Options(useGeneratedKeys = true, keyProperty="idevents")
    int insert(Event record);

    @InsertProvider(type=EventsSqlProvider.class, method="insertSelective")
    int insertSelective(Event record);

    @SelectProvider(type=EventsSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="idEvents", property="idevents", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
		@Result(column="city", property="city", javaType=City.class, one=@One(select="it.irondev.appturismo.dao.CityMapper.selectByPrimaryKey")),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="location", property="location", jdbcType=JdbcType.VARCHAR),
        @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
        @Result(column="start_date", property="startDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end_date", property="endDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="web", property="web", jdbcType=JdbcType.VARCHAR),
		@Result(column="type", property="type", javaType=Eventstype.class, one=@One(select="it.irondev.appturismo.dao.EventstypeMapper.selectByPrimaryKey")),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
		@Result(column="gallery", property="gallery", javaType=Gallery.class, one=@One(select="it.irondev.appturismo.dao.GalleryMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey"))
    })
    List<Event> selectByExample(EventsExample example);

    @Select({
        "select",
        "idEvents, name, city, address, location, position, start_date, end_date, type, ",
        "description, web, gallery,language",
        "from Events",
        "where idEvents = #{idevents,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="idEvents", property="idevents", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
		@Result(column="city", property="city", javaType=City.class, one=@One(select="it.irondev.appturismo.dao.CityMapper.selectByPrimaryKey")),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="location", property="location", jdbcType=JdbcType.VARCHAR),
        @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
        @Result(column="start_date", property="startDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end_date", property="endDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="web", property="web", jdbcType=JdbcType.VARCHAR),
		@Result(column="type", property="type", javaType=Eventstype.class, one=@One(select="it.irondev.appturismo.dao.EventstypeMapper.selectByPrimaryKey")),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
		@Result(column="gallery", property="gallery", javaType=Gallery.class, one=@One(select="it.irondev.appturismo.dao.GalleryMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey"))
    })
    Event selectByPrimaryKey(Integer idevents);

    @UpdateProvider(type=EventsSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Event record, @Param("example") EventsExample example);

    @UpdateProvider(type=EventsSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Event record, @Param("example") EventsExample example);

    @UpdateProvider(type=EventsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Event record);

    @Update({
        "update Events",
        "set name = #{name,jdbcType=VARCHAR},",
          "city = #{city.idcity,jdbcType=INTEGER},",
          "address = #{address,jdbcType=VARCHAR},",
          "location = #{location,jdbcType=VARCHAR},",
          "position = #{position,jdbcType=VARCHAR},",
          "start_date = #{startDate,jdbcType=TIMESTAMP},",
          "end_date = #{endDate,jdbcType=TIMESTAMP},",
          "type = #{type.ideventstype,jdbcType=INTEGER},",
          "description = #{description,jdbcType=VARCHAR},",
          "web = #{web,jdbcType=VARCHAR},",
          "gallery = #{gallery.idgallery,jdbcType=INTEGER},",
          "language = #{language.idlanguage,jdbcType=INTEGER}",
        "where idEvents = #{idevents,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Event record);
}